#pragma once
#include <string>
#include "record.hpp"

template<class Record>
class base_ostream /*: public std::ostream*/
{
public:
	base_ostream & operator << (std::string str)
	{
		ostream_->write(str);
		return *this;
	}

	base_ostream& operator << (int value)
	{
		ostream_->write(value);
		return *this;
	}

public:
	Record * get_stream() { return ostream_; }

private:
	Record * ostream_;
};



template<class LoggerT>
class record_dump : public base_ostream<record>
{
private:
	using logger_type = LoggerT;
	using base_type = base_ostream<record>;

public:
	record_dump(logger_type lg) {}

	virtual ~record_dump()
	{
		if (logger_)
			logger_->push_logger(base_->get_stream()->get_record());
	}

private:
	logger_type * logger_;
	base_type* base_;
};


template<class LoggerType>
inline record_dump<LoggerType> make_record_dump(LoggerType lg)
{
	return record_dump<LoggerType>(lg); 
}


#define XLog(logger) make_record_dump(logger)